package com.smzd.framework.oauth2.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.smzd.core.dao.AbstractDao;
import com.smzd.core.domain.Many2Many;
import com.smzd.core.mappers.IMapper;
import com.smzd.framework.oauth2.domain.ClientApp;
import com.smzd.framework.oauth2.mappers.ClientAppMapper;

@Component
public class ClientAppDao extends AbstractDao<ClientApp> {
    @Autowired
    private ClientAppMapper mapper;

    @Override
    protected IMapper<ClientApp> getMapper() {
        return mapper;
    }

    public void saveAppClientResources(List<Many2Many> toAdd, List<Many2Many> toDel) {
        for (Many2Many cr : toAdd) {
            mapper.insertClientAppResource(cr);
        }
        for (Many2Many cr : toDel) {
            mapper.removeClientAppResource(cr);
        }
    }

    public void saveAppClientAuthorities(List<Many2Many> toAdd, List<Many2Many> toDel) {
        for (Many2Many cr : toAdd) {
            mapper.insertClientAppAuthority(cr);
        }
        for (Many2Many cr : toDel) {
            mapper.removeClientAppAuthority(cr);
        }
    }

    public ClientApp getClientAppByClientId(String clientId) {
        return mapper.getClientAppByClientId(clientId);
    }
}
